import json

import requests
from flask import Blueprint,request,jsonify

from applications.common.utils.http import remark_api

tomsg = Blueprint('tomsg', __name__, url_prefix='/tomsg')

@tomsg.route('/toaddmsg', methods=["POST"])
def toaddmsg():
    req_json=request.json
    print('req_json:',req_json)

    accesstock_url='https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=wx2be380fdde5b4d4f&secret=aab61b48e5b9b7d45485ac93feaa9107'

    access_res =requests.get(accesstock_url)

    access=access_res.json()
    access_token=access.get('access_token')
    # print('access',type(access))
    # access_token=access.get('access_token')
    # token=req_json.get('access_token')
    data = req_json.get('data')
    # data=json.dump(data)

    data = json.dumps(data)
    print('data:',data)
    headers={
        # 'Content-Type': 'application/json'
        "Content-Type": "application/x-www-form-urlencoded"
    }
    base_url='https://api.weixin.qq.com/cgi-bin/message/subscribe/send?access_token='+access_token
    print('data:',data)
    ret=requests.post(url=base_url,data=data,headers=headers)
    print(ret.text)
    return remark_api()
